package apis

import (
	"fmt"
	"gluenet/pkg/meta"
	glue2 "gluenet/pkg/platform/glue"
)

const (
	_applicationLevel = "application_level"
	_strategyLevel    = "strategy_level"
	_configKinds      = "config_kind"
	_kinds            = "kind"
	_instanceType     = "instance_type"
	_instanceStatus   = "instance_status"
	_mods             = "modes"

	_platfrom = "platform"
)

func defaultInfos() []string {
	return []string{_applicationLevel, _strategyLevel, _configKinds, _kinds, _instanceType, _instanceStatus, _platfrom, _mods}
}

func helmInfos() []string {
	return []string{_configKinds, _kinds, _mods}
}

func Modules() []string {
	return []string{ModuleDefault, ModuleHelm}
}

func ConfigKinds() []string {
	return []string{KindStrategy, KindApplication}
}

func Kinds() []string {
	return []string{meta.KindConfig, meta.KindInstance}
}

func Infos(mode string, info string) ([]string, error) {
	switch mode {
	case ModuleDefault:
		switch info {
		case _configKinds:
			return glue2.ConfigKinds(), nil
		case _applicationLevel:
			return glue2.ConfigApplicationLevels(), nil
		case _strategyLevel:
			return glue2.ConfigStrategyLevels(), nil
		case _kinds:
			return Kinds(), nil
		case _instanceType:
			return glue2.InstanceTypes(), nil
		case _instanceStatus:
			return glue2.InstanceStatus(), nil
		case _mods:
			return Modules(), nil
		case _platfrom:
			return Platforms(), nil
		default:
			return nil, fmt.Errorf("unknown info type %v must in %v", info, defaultInfos())
		}
	case ModuleHelm:
		switch info {
		case _configKinds:
			return glue2.ConfigKinds(), nil
		case _kinds:
			return Kinds(), nil
		case _mods:
			return Modules(), nil
		default:
			return nil, fmt.Errorf("unknown info type %v must in %v", info, helmInfos())
		}
	default:
		if info == _mods {
			return Modules(), nil
		}
		return nil, fmt.Errorf("unknown mode %v, must in %v", mode, Modules())
	}
}
